home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1997 December / PC Pro December 1997 CD-Rom coverdisc.iso / symantec / dbAnywh / JAVA.BIN / CLASSES.ZIP / sun / tools / tree / Expression.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-14  |  7.7 KB  |  394 lines

  1. package sun.tools.tree;
  2.  
  3. import java.io.PrintStream;
  4. import java.util.Hashtable;
  5. import sun.tools.asm.Assembler;
  6. import sun.tools.asm.Label;
  7. import sun.tools.java.AmbiguousField;
  8. import sun.tools.java.ClassDeclaration;
  9. import sun.tools.java.ClassDefinition;
  10. import sun.tools.java.ClassNotFound;
  11. import sun.tools.java.CompilerError;
  12. import sun.tools.java.Constants;
  13. import sun.tools.java.Environment;
  14. import sun.tools.java.FieldDefinition;
  15. import sun.tools.java.Identifier;
  16. import sun.tools.java.Type;
  17.  
  18. public class Expression extends Node {
  19.    Type type;
  20.  
  21.    Expression(int var1, int var2, Type var3) {
  22.       super(var1, var2);
  23.       this.type = var3;
  24.    }
  25.  
  26.    int precedence() {
  27.       return super.op < Constants.opPrecedence.length ? Constants.opPrecedence[super.op] : 100;
  28.    }
  29.  
  30.    public Expression order() {
  31.       return this;
  32.    }
  33.  
  34.    public boolean isConstant() {
  35.       return false;
  36.    }
  37.  
  38.    public Object getValue() {
  39.       return null;
  40.    }
  41.  
  42.    public boolean equals(int var1) {
  43.       return false;
  44.    }
  45.  
  46.    public boolean equals(boolean var1) {
  47.       return false;
  48.    }
  49.  
  50.    public boolean equals(Identifier var1) {
  51.       return false;
  52.    }
  53.  
  54.    public boolean equalsDefault() {
  55.       return false;
  56.    }
  57.  
  58.    Type toType(Environment var1, Context var2) {
  59.       var1.error(super.where, "invalid.type.expr");
  60.       return Type.tError;
  61.    }
  62.  
  63.    public boolean fitsType(Environment var1, Type var2) {
  64.       try {
  65.          return var1.isMoreSpecific(this.type, var2);
  66.       } catch (ClassNotFound var3) {
  67.          return false;
  68.       }
  69.    }
  70.  
  71.    public long checkValue(Environment var1, Context var2, long var3, Hashtable var5) {
  72.       return var3;
  73.    }
  74.  
  75.    public long checkInitializer(Environment var1, Context var2, long var3, Type var5, Hashtable var6) {
  76.       return this.checkValue(var1, var2, var3, var6);
  77.    }
  78.  
  79.    public long check(Environment var1, Context var2, long var3, Hashtable var5) {
  80.       throw new CompilerError("check failed");
  81.    }
  82.  
  83.    public long checkLHS(Environment var1, Context var2, long var3, Hashtable var5) {
  84.       var1.error(super.where, "invalid.lhs.assignment");
  85.       this.type = Type.tError;
  86.       return var3;
  87.    }
  88.  
  89.    public long checkAssignOp(Environment var1, Context var2, long var3, Hashtable var5, Expression var6) {
  90.       if (var6 instanceof IncDecExpression) {
  91.          var1.error(super.where, "invalid.arg", Constants.opNames[var6.op]);
  92.       } else {
  93.          var1.error(super.where, "invalid.lhs.assignment");
  94.       }
  95.  
  96.       this.type = Type.tError;
  97.       return var3;
  98.    }
  99.  
  100.    public ConditionVars checkCondition(Environment var1, Context var2, long var3, Hashtable var5) {
  101.       ConditionVars var6 = new ConditionVars();
  102.       this.checkCondition(var1, var2, var3, var5, var6);
  103.       return var6;
  104.    }
  105.  
  106.    public void checkCondition(Environment var1, Context var2, long var3, Hashtable var5, ConditionVars var6) {
  107.       var6.vsTrue = var6.vsFalse = this.checkValue(var1, var2, var3, var5);
  108.    }
  109.  
  110.    Expression eval() {
  111.       return this;
  112.    }
  113.  
  114.    Expression simplify() {
  115.       return this;
  116.    }
  117.  
  118.    public Expression inline(Environment var1, Context var2) {
  119.       return null;
  120.    }
  121.  
  122.    public Expression inlineValue(Environment var1, Context var2) {
  123.       return this;
  124.    }
  125.  
  126.    public Expression inlineLHS(Environment var1, Context var2) {
  127.       return null;
  128.    }
  129.  
  130.    public int costInline(int var1) {
  131.       return 1;
  132.    }
  133.  
  134.    void codeBranch(Environment var1, Context var2, Assembler var3, Label var4, boolean var5) {
  135.       if (this.type.isType(0)) {
  136.          this.codeValue(var1, var2, var3);
  137.          var3.add(super.where, var5 ? 154 : 153, var4);
  138.       } else {
  139.          throw new CompilerError("codeBranch " + Constants.opNames[super.op]);
  140.       }
  141.    }
  142.  
  143.    public void codeValue(Environment var1, Context var2, Assembler var3) {
  144.       if (this.type.isType(0)) {
  145.          Label var4 = new Label();
  146.          Label var5 = new Label();
  147.          this.codeBranch(var1, var2, var3, var4, true);
  148.          var3.add(super.where, 18, new Integer(0));
  149.          var3.add(super.where, 167, var5);
  150.          var3.add(var4);
  151.          var3.add(super.where, 18, new Integer(1));
  152.          var3.add(var5);
  153.       } else {
  154.          throw new CompilerError("codeValue");
  155.       }
  156.    }
  157.  
  158.    public void code(Environment var1, Context var2, Assembler var3) {
  159.       this.codeValue(var1, var2, var3);
  160.       switch (this.type.getTypeCode()) {
  161.          case 5:
  162.          case 7:
  163.             var3.add(super.where, 88);
  164.             return;
  165.          default:
  166.             var3.add(super.where, 87);
  167.          case 11:
  168.       }
  169.    }
  170.  
  171.    int codeLValue(Environment var1, Context var2, Assembler var3) {
  172.       this.print(System.out);
  173.       throw new CompilerError("invalid lhs");
  174.    }
  175.  
  176.    void codeLoad(Environment var1, Context var2, Assembler var3) {
  177.       this.print(System.out);
  178.       throw new CompilerError("invalid load");
  179.    }
  180.  
  181.    void codeStore(Environment var1, Context var2, Assembler var3) {
  182.       this.print(System.out);
  183.       throw new CompilerError("invalid store");
  184.    }
  185.  
  186.    void codeAppend(Environment var1, Context var2, Assembler var3, ClassDeclaration var4) {
  187.       try {
  188.          this.codeValue(var1, var2, var3);
  189.          Type[] var5 = new Type[]{this.type};
  190.          ClassDefinition var6 = var2.field.getClassDefinition();
  191.          FieldDefinition var7 = var4.getClassDefinition(var1).matchMethod(var1, var6, Constants.idAppend, var5);
  192.          var3.add(super.where, 182, var7);
  193.       } catch (ClassNotFound var8) {
  194.          throw new CompilerError(var8);
  195.       } catch (AmbiguousField var9) {
  196.          throw new CompilerError(var9);
  197.       }
  198.    }
  199.  
  200.    void codeDup(Environment var1, Context var2, Assembler var3, int var4, int var5) {
  201.       switch (var4) {
  202.          case 0:
  203.             return;
  204.          case 1:
  205.             switch (var5) {
  206.                case 0:
  207.                   var3.add(super.where, 89);
  208.                   return;
  209.                case 1:
  210.                   var3.add(super.where, 90);
  211.                   return;
  212.                case 2:
  213.                   var3.add(super.where, 91);
  214.                   return;
  215.                default:
  216.                   throw new CompilerError("can't dup: " + var4 + ", " + var5);
  217.             }
  218.          case 2:
  219.             switch (var5) {
  220.                case 0:
  221.                   var3.add(super.where, 92);
  222.                   return;
  223.                case 1:
  224.                   var3.add(super.where, 93);
  225.                   return;
  226.                case 2:
  227.                   var3.add(super.where, 94);
  228.                   return;
  229.             }
  230.       }
  231.  
  232.       throw new CompilerError("can't dup: " + var4 + ", " + var5);
  233.    }
  234.  
  235.    void codeConversion(Environment var1, Context var2, Assembler var3, Type var4, Type var5) {
  236.       int var6 = var4.getTypeCode();
  237.       int var7 = var5.getTypeCode();
  238.       switch (var7) {
  239.          case 0:
  240.             if (var6 == 0) {
  241.                return;
  242.             }
  243.             break;
  244.          case 1:
  245.             if (var6 != 1) {
  246.                this.codeConversion(var1, var2, var3, var4, Type.tInt);
  247.                var3.add(super.where, 145);
  248.             }
  249.  
  250.             return;
  251.          case 2:
  252.             if (var6 != 2) {
  253.                this.codeConversion(var1, var2, var3, var4, Type.tInt);
  254.                var3.add(super.where, 146);
  255.             }
  256.  
  257.             return;
  258.          case 3:
  259.             if (var6 != 3) {
  260.                this.codeConversion(var1, var2, var3, var4, Type.tInt);
  261.                var3.add(super.where, 147);
  262.             }
  263.  
  264.             return;
  265.          case 4:
  266.             switch (var6) {
  267.                case 1:
  268.                case 2:
  269.                case 3:
  270.                case 4:
  271.                   return;
  272.                case 5:
  273.                   var3.add(super.where, 136);
  274.                   return;
  275.                case 6:
  276.                   var3.add(super.where, 139);
  277.                   return;
  278.                case 7:
  279.                   var3.add(super.where, 142);
  280.                   return;
  281.                default:
  282.                   throw new CompilerError("codeConversion: " + var6 + ", " + var7);
  283.             }
  284.          case 5:
  285.             switch (var6) {
  286.                case 1:
  287.                case 2:
  288.                case 3:
  289.                case 4:
  290.                   var3.add(super.where, 133);
  291.                   return;
  292.                case 5:
  293.                   return;
  294.                case 6:
  295.                   var3.add(super.where, 140);
  296.                   return;
  297.                case 7:
  298.                   var3.add(super.where, 143);
  299.                   return;
  300.                default:
  301.                   throw new CompilerError("codeConversion: " + var6 + ", " + var7);
  302.             }
  303.          case 6:
  304.             switch (var6) {
  305.                case 1:
  306.                case 2:
  307.                case 3:
  308.                case 4:
  309.                   var3.add(super.where, 134);
  310.                   return;
  311.                case 5:
  312.                   var3.add(super.where, 137);
  313.                   return;
  314.                case 6:
  315.                   return;
  316.                case 7:
  317.                   var3.add(super.where, 144);
  318.                   return;
  319.                default:
  320.                   throw new CompilerError("codeConversion: " + var6 + ", " + var7);
  321.             }
  322.          case 7:
  323.             switch (var6) {
  324.                case 1:
  325.                case 2:
  326.                case 3:
  327.                case 4:
  328.                   var3.add(super.where, 135);
  329.                   return;
  330.                case 5:
  331.                   var3.add(super.where, 138);
  332.                   return;
  333.                case 6:
  334.                   var3.add(super.where, 141);
  335.                   return;
  336.                case 7:
  337.                   return;
  338.             }
  339.          case 8:
  340.          default:
  341.             break;
  342.          case 9:
  343.             switch (var6) {
  344.                case 8:
  345.                   return;
  346.                case 9:
  347.                case 10:
  348.                   try {
  349.                      if (!var1.implicitCast(var4, var5)) {
  350.                         var3.add(super.where, 192, var5);
  351.                      }
  352.  
  353.                      return;
  354.                   } catch (ClassNotFound var10) {
  355.                      throw new CompilerError(var10);
  356.                   }
  357.                default:
  358.                   throw new CompilerError("codeConversion: " + var6 + ", " + var7);
  359.             }
  360.          case 10:
  361.             switch (var6) {
  362.                case 8:
  363.                   return;
  364.                case 9:
  365.                case 10:
  366.                   try {
  367.                      if (!var1.implicitCast(var4, var5)) {
  368.                         var3.add(super.where, 192, var1.getClassDeclaration(var5));
  369.                         return;
  370.                      }
  371.  
  372.                      return;
  373.                   } catch (ClassNotFound var9) {
  374.                      throw new CompilerError(var9);
  375.                   }
  376.             }
  377.       }
  378.  
  379.       throw new CompilerError("codeConversion: " + var6 + ", " + var7);
  380.    }
  381.  
  382.    public boolean firstConstructor() {
  383.       return false;
  384.    }
  385.  
  386.    public Expression copyInline(Context var1) {
  387.       return (Expression)((Node)this).clone();
  388.    }
  389.  
  390.    public void print(PrintStream var1) {
  391.       var1.print(Constants.opNames[super.op]);
  392.    }
  393. }
  394.